<?php
class Cl_Home extends WdkClass 
{
	protected
		/******************************************************/
		//	원본 테이블 정보
		/******************************************************/
		$home_seq			= 0		,	//	
		$home_type			= 0		,	//	
		$home_index			= 0		,	//	
		$home_data			= ''	,	//	
		$home_insert_time	= 0		,	//	
		$home_del_flag		= 'F'	;	//	
		/******************************************************/
		//	추가 정보
		/******************************************************/
	
	/**
	 * 	
	 */
	function __construct()
	{
		parent::__construct();
		self::getDbo();
	}
	
	/**
	 *	
	 */
	public function __init($data)
	{
		parent::__init($data);
		self::dformat();
	}
	
	/**
	 *	
	 */
	public function load($home_seq)
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		self::__init($dbo->cLoad($home_seq));
	}
	
	/**
	 *	
	 */
	public function dformat()
	{
		if(is_string($this->home_data))
		{
			$this->home_data = (array) json_decode($this->home_data, 1);
		}
	}
	
	/**
	 * 
	 */
	public function autoUpdate($log='')
	{
		if((int)$this->home_seq > 0)
		{
			$this->update($log);
		}
		else
		{
			$this->insert($log);
		}
	}
	
	/**
	 *	
	 */
	public function insert($log='Insert')
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		
		$this->home_insert_time	= time();
		$this->home_del_flag		= 'F';
		
		$data = array(	'home_type'			=>	$this->home_type,
						'home_index'		=>	$this->home_index,
						'home_data'			=>	json_encode((array) $this->home_data),
						'home_insert_time'	=>	$this->home_insert_time,
						'home_del_flag'		=>	$this->home_del_flag
					);
		$this->home_seq = $dbo->insert($data);
		$this->backup($log);
	}
	
	/**
	 * 
	 */
	public function update($log='update')
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		
		$data = array(	'home_data'			=>	json_encode((array) $this->home_data)
					);
		$dbo->update($data, array("home_seq = ".$this->home_seq));
		$this->backup($log);
	}
	
	/**
	 * 
	 */
	public function delete($log='delete')
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		$dbo->delete(array("home_seq = ".$this->home_seq));
		$this->backup($log);
	}
	
	/**
	 *	
	 */
	private function backup($log='')
	{
// 		/*------------------------------------------------------------*/
// 		$dbo = self::getDbo();
// 		/*------------------------------------------------------------*/
// 		$dbo->log($this->user_seq, $log, $this->backup_data);
	}
	
	/**
	 * 
	 */
	public function getDbo()
	{
		return Wdk::model(substr(__CLASS__, 3));
	}
}